package 周赛._279;

/**
 * @author 会玩的洋芋
 * https://leetcode-cn.com/problems/sort-even-and-odd-indices-independently/
 */
public class _6000_对奇偶下标分别排序 {
    public int[] sortEvenOdd(int[] nums) {
        int n = nums.length;
        for (int i = 0; i < n; i++) {
            for (int j = i + 2; j < n; j += 2) {
                if (i % 2 == 0) {
                    if (nums[i] > nums[j]) {
                        int temp = nums[i];
                        nums[i] = nums[j];
                        nums[j] = temp;
                    }
                } else {
                    if (nums[i] < nums[j]) {
                        int temp = nums[i];
                        nums[i] = nums[j];
                        nums[j] = temp;
                    }
                }
            }
        }
        return nums;
    }
}
